﻿using DX_Recognize.Common;
using DX_Recognize.Entitys;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace DX_Recognize.View
{
    public partial class EGPWindow : Form
    {
        public EGPProcessinfo infos = null;
        List<int> dimList = new List<int>() { 0, 12, 16, 20, 25, 30, 35, 40, 50 };
        public EGPWindow()
        {
            InitializeComponent();
            this.EGPItemDimComboBox.DataSource = dimList;
            this.Hide();
        }

        public void ResetUI()
        {
            infos = AssemblyShareData.egpProcessinfo;
            this.LengthBox.Text = infos.length.ToString();
            this.NumBox.Text = infos.num.ToString();
            this.HoleLBox.Text = infos.holeL.ToString();
            this.HoleWBox.Text = infos.holeW.ToString();
            this.NoAvailItemCheckBox.Checked = infos.noFurnishF;
            this.EGPItemDimComboBox.SelectedItem = infos.dim;
        }
        public void SetUI()
        {
            ResetUI();
            if (this.WindowState == FormWindowState.Minimized)
                this.WindowState = FormWindowState.Normal;
            this.Show();
        }

        private void EGPWindow_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.Hide();
            e.Cancel = true;
        }

        private void CancelBtn_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void ComfirmBtn_Click(object sender, EventArgs e)
        {
            infos.noFurnishF = this.NoAvailItemCheckBox.Checked;
            Boolean F1 = Int32.TryParse(this.LengthBox.Text, out int Length);
            if (F1)
                infos.length = Length;
            Boolean F2 = Int32.TryParse(this.NumBox.Text, out int Num);
            if (F2)
                infos.num = Num;
            Boolean F3 = Double.TryParse(this.HoleLBox.Text, out double HoleL);
            if (F3)
                infos.holeL = HoleL;
            Boolean F4 = Double.TryParse(this.HoleWBox.Text, out double HoleW);
            if (F4)
                infos.holeW = HoleW;
            Boolean F5 = Int32.TryParse(this.EGPItemDimComboBox.SelectedText, out int Dim);
           if(F5)
                infos.dim = Dim;
            this.Hide();
        }
    }
}
